<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InnerProduct">

    <Style TargetType="local:ColorPickr">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ColorPickr">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Border.Resources>
                            <local:ColorToHex x:Key="ColorToHex" />
                            <local:ByteToString x:Key="ByteToString" />
                            <local:ColorToBrush x:Key="ColorToBrush" />
                        </Border.Resources>
                            <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Ellipse Fill="White" />
                            <local:ColorWheel Margin="1,1,1,1" ColorHSV="{Binding ColorHSV, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay }"/>
                            <local:Slider Width="14" Margin="5,2,0,2" Grid.Column="1" Color="{Binding ColorHSV,  RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay }" />
                            <Grid VerticalAlignment="Top" Grid.ColumnSpan="2" Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,7,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <TextBox Text="{Binding R, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ByteToString}, Mode=TwoWay}" Grid.Column="0" Margin="2,0,2,4" BorderBrush="Red" BorderThickness="0,0,4,0"/>
                                <TextBox Text="{Binding G, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ByteToString}, Mode=TwoWay}" Grid.Column="1" Margin="2,0,2,4" BorderBrush="#FF10FF00" BorderThickness="0,0,4,0"/>
                                <TextBox Text="{Binding B, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ByteToString}, Mode=TwoWay}" Grid.Column="2" Margin="2,0,2,4" BorderBrush="#FF007DFF" BorderThickness="0,0,4,0"/>
                                <TextBox Text="{Binding A, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ByteToString}, Mode=TwoWay}" Grid.Row="1" Margin="2,0" BorderThickness="0,0,4,0">
                                    <TextBox.BorderBrush>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Offset="1"/>
                                            <GradientStop Color="Black"/>
                                        </LinearGradientBrush>
                                    </TextBox.BorderBrush>
                                </TextBox>
                                <TextBox Text="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorToHex}}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="6,0,6,0" BorderThickness="0" IsReadOnly="True"/>
                            </Grid>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
